/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**package manejadores;

import entidades.Centro;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import persistencia.Conexion;

public class ManejadorDeIngenieriaSocial {

    private Conexion con;
    private static ManejadorDeIngenieriaSocial instancia;
    private ArrayList <Centro> centros;
    private PreparedStatement ps;
    private ResultSet rs;

    public ManejadorDeIngenieriaSocial (){
        con = Conexion.getInstancia();
    }

    public static ManejadorDeIngenieriaSocial getInstancia(){
        if(instancia==null){
            instancia=new ManejadorDeIngenieriaSocial();
        }

        return instancia;
    }

    public ArrayList <Centro> getCentros(){
        centros = new ArrayList<Centro>();
        String sql = "select * from centro";
        ps=(PreparedStatement) con.hacerEnunciado(sql);
        rs=con.hacerConsulta(sql);
        try {
            while (rs.next()) {
                Centro centro = new Centro(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getInt(5), rs.getInt(6), rs.getString(7), rs.getString(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12));
                centros.add(centro);
            }
        } catch (SQLException ex) {
           JOptionPane.showMessageDialog(null, "Error de tipo Sql");
        }
        return centros;
    }

    public int agregarCentro(Centro centro){
        int fila = 0;
        String sql = "INSERT INTO ingenieria_social.centro (id_centro, fase, nombre_centro, telefono_centro, id_supervisor, id_ingeniero,"+ 
	"calle, numero, dist_municipal, paraje, seccion, sector) VALUES(0, ?,?, ?, ?, ?, ?, ?, ?,?, ?, ?);";
        ps=(PreparedStatement)con.hacerEnunciado(sql);
        try {
            ps.setString(1, centro.getFaseCentro());
            ps.setString(2, centro.getNombreCentro());
            ps.setString(3, centro.getTelefono());
            ps.setInt(4, centro.getIdSupervisor());
            ps.setInt(5, centro.getIdSupervisor());
            ps.setString(6, centro.getCalle());
            ps.setString(7, centro.getNumero());
            ps.setString(8, centro.getDistMunicipal());
            ps.setString(9, centro.getParaje());
            ps.setString(10, centro.getSeccion());
            ps.setString(11, centro.getSector());
            fila = ps.executeUpdate();
         } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error de tipo Sql");
         }
         return fila;

   }

    public int eliminarCentro(int id){
        int fila =0;
        String sql ="delete from centro where id_centro =?";
        ps=(PreparedStatement)con.hacerEnunciado(sql);
        try {
            ps.setInt(1, id);
            fila = ps.executeUpdate();
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error de tipo Sql");
        }
        return fila;
    }

    public int modificarCentro (Centro centro){
        int fila =0;
        String sql="UPDATE ingenieria_social.centro SET  fase =? , nombre_centro = ? , telefono_centro = ? , id_supervisor = ?,"+
                "id_ingeniero = ? , calle = ? , numero = ? , dist_municipal = ? ,paraje = ?,seccion = ?,sector = ? WHERE id_centro = ?";
        ps=(PreparedStatement) con.hacerEnunciado(sql);
         try {
            ps.setString(1, centro.getFaseCentro());
            ps.setString(2, centro.getNombreCentro());
            ps.setString(3, centro.getTelefono());
            ps.setInt(4, centro.getIdSupervisor());
            ps.setInt(5, centro.getIdSupervisor());
            ps.setString(6, centro.getCalle());
            ps.setString(7, centro.getNumero());
            ps.setString(8, centro.getDistMunicipal());
            ps.setString(9, centro.getParaje());
            ps.setString(10, centro.getSeccion());
            ps.setString(11, centro.getSector());
            ps.setInt(12, centro.getIdCentro());
            fila = ps.executeUpdate();
         } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, "Error de tipo Sql");
         }
         return fila;

    }

}
*/
